
const { Readable } = require('stream')
function streamToString(stream) {
    return new Promise((resolve, reject) => {
        let body = ''
        stream.on('error', reject)
        stream.on('data', chunk => body += chunk)
        stream.on('end', () => resolve(body))
    })
}

function stringToStream(text) {
    const stream = new Readable()
    stream.push(text)
    stream.push(null)
    return stream
}

module.exports = {
    streamToString,
    stringToStream
}